package com.gzmpc.kafka.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author:lizhicheng
 * @email:lizhicheng@gzmpc.com
 * @date:2024-03-22 15:59:59
 */
@Component
@Slf4j
public class KafkaConsumer {
    //不指定group，默认取yml里配置的
    @KafkaListener(topics = {"test"})
    public void onMessage1(ConsumerRecord<?, ?> consumerRecord) {
        Optional<?> optional = Optional.ofNullable(consumerRecord.value());
        if (optional.isPresent()) {
            Object msg = optional.get();
            log.info("kafka consumer receive message : {}", msg);
            //test1
            //test2
            //test3
            //test4
            //test5
        }
    }

}
